package com.xgst.runningmanager

import android.content.Intent
import android.text.TextUtils
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.TimeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.hjq.http.EasyHttp
import com.hjq.http.listener.OnHttpListener
import com.xgst.baselib.BaseActivity
import com.xgst.runningmanager.adapter.OrderListAdapter
import com.xgst.runningmanager.bean.OrderBean
import com.xgst.runningmanager.bean.OrderErrorBean
import com.xgst.runningmanager.bean.OrderListBean
import com.xgst.runningmanager.bean.Row
import com.xgst.runningmanager.databinding.ActivityOrderListBinding
import com.xgst.runningmanager.http.api.ErrorListAPI
import com.xgst.runningmanager.http.api.LookListAPI

class ErrorListActivity:BaseActivity<ActivityOrderListBinding>(), OnItemClickListener {
    private val eventTypes = arrayOf("衣着问题", "言语文明问题", "上班时间脱岗", "其他")

    private lateinit var adapter:OrderListAdapter

    override fun init() {
        binding.tvTitle.text = "失范行为工单列表"
        binding.recyclerView.layoutManager = LinearLayoutManager(this)
        adapter = OrderListAdapter()
        binding.recyclerView.adapter = adapter
        data()
        adapter.setOnItemClickListener(this)
    }

    fun data(){
        EasyHttp.post(this)
            .api(ErrorListAPI())
            .request(object : OnHttpListener<OrderErrorBean>{
                override fun onHttpSuccess(bean: OrderErrorBean) {
                    adapter.setNewInstance(bean.result.rows)
                }

                override fun onHttpFail(p0: Throwable?) {

                }
            })
    }

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
        val item = adapter.getItem(position) as Row
        val intent = Intent(this,ErrorDetailActivity::class.java)
        if(!TextUtils.isEmpty(item.category)){
            val i = item.category.toInt()
            if(i < eventTypes.size){
               intent.putExtra("category",eventTypes[i])
            }
        }
        intent.putExtra("tvUseName",item.submitUser)
        intent.putExtra("title",item.title)
        intent.putExtra("tvQ",item.description)
        intent.putExtra("attachFile",item.attachFile)
        intent.putExtra("tvTime", TimeUtils.millis2String(item.submitTime))
        startActivity(intent)
    }
}